#pragma once

#include <stdexcept>

template<class Node>
class NodeStack
{
    Node ** m_stack;
    size_t m_stackPtr;
    size_t m_stackSize;

public:
    NodeStack(size_t stackSize)
    {
        m_stack = new Node * [stackSize];
        m_stackSize = stackSize;
        m_stackPtr = 0;
    }

    ~NodeStack()
    {
        delete [] m_stack;
    }

    void push(Node * node)
    {
    	if(m_stackPtr >= m_stackSize)
            throw std::runtime_error("Nodes stack overflow");

        m_stack[m_stackPtr++] = node;
    }

    Node * pop()
    {
        if(m_stackPtr == 0)
            throw std::runtime_error("Retrieving from empty stack");

        return m_stack[--m_stackPtr];
    }

    bool empty() const
    {
        return (m_stackPtr == 0);
    }
};
